class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> memo;
        vector<int> result;
        for (int n : nums1) memo.insert(n);
        for (int n : nums2)
        {
            auto it = memo.find(n);
            if(it != memo.end())
            {
                result.push_back(n);
                memo.erase(n);
            }
        }
        return result;
    }
};
